package com.cn.kabalifeuser.ui.service.adapter;

import android.text.TextUtils;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.ui.service.bean.BusinessListBean;
import com.cn.kabalifeuser.utils.GlideUtil;
import com.cn.kabalifeuser.view.xx.MyRatingBar;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by 晓林 on 2020/9/11.
 * function:
 */
public class MerchantsListAdapter extends BaseQuickAdapter<BusinessListBean.ResultBean.DataBean, BaseViewHolder> {
    public MerchantsListAdapter(int layoutResId, @Nullable List<BusinessListBean.ResultBean.DataBean> data) {
        super(layoutResId, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, final BusinessListBean.ResultBean.DataBean item) {

        ImageView cover_url = helper.getView(R.id.cover_url);
        GlideUtil.ImageLoad(this.mContext, item.getCover_url(), cover_url);

        helper.setText(R.id.tv_order_count, "单量：" + item.getOrder_count());
        ViewGroup.LayoutParams params = cover_url.getLayoutParams();//得到item的LayoutParams布局参数

        params.height = ((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, helper.getPosition() % 2 == 0 ? 200 : 180, this.mContext.getResources().getDisplayMetrics()));//把随机的高度赋予item布局
        cover_url.setLayoutParams(params);//把params设置给item布局
        MyRatingBar ratingbar = helper.getView(R.id.ratingbar);
        ratingbar.setEnabled(false);
        ratingbar.setRating(TextUtils.isEmpty(item.getFraction()) ? 0 : Float.parseFloat(item.getFraction()));
        helper.setText(R.id.title, item.getTitle())
                .setText(R.id.tv_juli, item.getJuli());
        List<String> mListStr = new ArrayList<>();
        for (int i = 0; i < item.getServices().size(); i++) {
            mListStr.add(item.getServices().get(i).getTitle());
        }
        RecyclerView rv_type_list = helper.getView(R.id.rv_type_list);
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(this.mContext);
        layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
        layoutManager1.setSmoothScrollbarEnabled(true);
        layoutManager1.setAutoMeasureEnabled(true);
        rv_type_list.setLayoutManager(layoutManager1);
//        rv_type_list.setNestedScrollingEnabled(false);
        ServicesTypeTitleAdapter servicesTypeTitleAdapter = new ServicesTypeTitleAdapter(R.layout.list_item_type, mListStr);
        //给RecyclerView设置适配器
        rv_type_list.setAdapter(servicesTypeTitleAdapter);
    }


}
